﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaseData.Infrastructure.Interfaces
{
    /// <summary>
    /// 仓储接口
    /// </summary>
    /// <typeparam name="T">实体</typeparam>
    public interface IBaseRepository<T> where T : class
    {
        /// <summary>
        /// 数据库上下文
        /// </summary>
        DataDbContext DB { get; }
        /// <summary>
        /// 获取全部
        /// </summary>
        /// <returns>返回集合</returns>
        IQueryable<T> GetAll();
        Task<T> GetById(int id);
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>受影响行数</returns>
        Task<int> AddAsync(T entity);
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="entities">实体集合</param>
        /// <returns>受影响行数</returns>
        Task<int> AddRange(IEnumerable<T> entities);
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>受影响行数</returns>
        Task<int> UpdateAsync(T entity);
        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="entities">实体集合</param>
        /// <returns>受影响行数</returns>
        Task<int> UpdateRange(IEnumerable<T> entities);

        Task<int> DeleteAsync(T entity);
        Task<int> DeleteRange(IEnumerable<T> entities);
    }
}
